#include <iostream>
#include <stdio.h>

/*
 * 识别派生函数		P145
 */

class Base
{
	public:
		void demo(void) {
			printf("Base demon\n");
		}

		void demo_2(void) {
			printf("Base demon_2\n");
		}
};

class Derived : public Base
{
	public:
		void derive_demo(void) {
			printf("Derived demon\n");
		}

		void derive_demo_2(void) {
			printf("Derived demon_2\n");
		}
};

int main()
{
	Base p;

	printf("%d %d\n", sizeof(class Base), sizeof(class Derived));	// 1	1
	
	p.demo();
	p.demo_2();

	Derived d;

	d.demo();
	d.demo_2();

	d.derive_demo();
	d.derive_demo_2();
}

/*
	Base demon
	Base demon_2
	Base demon
	Base demon_2
	Derived demon
	Derived demon_2
 */

 #if 0

/*
 * intel
 */
00000000000011a9 <main>:
    11a9:	f3 0f 1e fa          	endbr64 
    11ad:	55                   	push   %rbp
    11ae:	48 89 e5             	mov    %rsp,%rbp
    11b1:	48 83 ec 10          	sub    $0x10,%rsp		// rsp-=0x10
    11b5:	64 48 8b 04 25 28 00 	mov    %fs:0x28,%rax
    11bc:	00 00 
    11be:	48 89 45 f8          	mov    %rax,-0x8(%rbp)		// rbp-0x8=rax
    11c2:	31 c0                	xor    %eax,%eax		// eax=0
    11c4:	48 8d 45 f6          	lea    -0xa(%rbp),%rax		// rax=rbp-0xa
    11c8:	48 89 c7             	mov    %rax,%rdi		// rdi=rax
    11cb:	e8 be 00 00 00       	callq  128e <_ZN4Base4demoEv>	// base.demo(rdi)
    11d0:	48 8d 45 f6          	lea    -0xa(%rbp),%rax		// rax=rbp-0xa
    11d4:	48 89 c7             	mov    %rax,%rdi		// rdi=rax
    11d7:	e8 d2 00 00 00       	callq  12ae <_ZN4Base6demo_2Ev>	// base.demo_2(rdi)
    11dc:	48 8d 45 f7          	lea    -0x9(%rbp),%rax		// rax=rbp-0x9			sizeof(class Base)=1
    11e0:	48 89 c7             	mov    %rax,%rdi		// rdi=rax
    11e3:	e8 a6 00 00 00       	callq  128e <_ZN4Base4demoEv>	// base.demo(rdi)
    11e8:	48 8d 45 f7          	lea    -0x9(%rbp),%rax		// rax=rbp-0x9
    11ec:	48 89 c7             	mov    %rax,%rdi		// rdi=rax
    11ef:	e8 ba 00 00 00       	callq  12ae <_ZN4Base6demo_2Ev>	// base.demo_2(rdi)
    11f4:	48 8d 45 f7          	lea    -0x9(%rbp),%rax		// rax=rbp-x09
    11f8:	48 89 c7             	mov    %rax,%rdi		// rdi=rax
    11fb:	e8 ce 00 00 00       	callq  12ce <_ZN7Derived11derive_demoEv>	// deriver_demo(rdi)
    1200:	48 8d 45 f7          	lea    -0x9(%rbp),%rax		// rax=rbp-0x9
    1204:	48 89 c7             	mov    %rax,%rdi		// rdi=rax
    1207:	e8 e2 00 00 00       	callq  12ee <_ZN7Derived13derive_demo_2Ev>	// derive_demo_2(rdi)
    120c:	b8 00 00 00 00       	mov    $0x0,%eax
    1211:	48 8b 55 f8          	mov    -0x8(%rbp),%rdx
    1215:	64 48 33 14 25 28 00 	xor    %fs:0x28,%rdx
    121c:	00 00 
    121e:	74 05                	je     1225 <main+0x7c>
    1220:	e8 6b fe ff ff       	callq  1090 <__stack_chk_fail@plt>
    1225:	c9                   	leaveq 
    1226:	c3                   	retq   

000000000000128e <_ZN4Base4demoEv>:
    128e:	f3 0f 1e fa          	endbr64 
    1292:	55                   	push   %rbp
    1293:	48 89 e5             	mov    %rsp,%rbp
    1296:	48 83 ec 10          	sub    $0x10,%rsp
    129a:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)
    129e:	48 8d 3d 60 0d 00 00 	lea    0xd60(%rip),%rdi        # 2005 <_ZStL19piecewise_construct+0x1>
    12a5:	e8 06 fe ff ff       	callq  10b0 <puts@plt>
    12aa:	90                   	nop
    12ab:	c9                   	leaveq 
    12ac:	c3                   	retq   
    12ad:	90                   	nop

00000000000012ae <_ZN4Base6demo_2Ev>:
    12ae:	f3 0f 1e fa          	endbr64 
    12b2:	55                   	push   %rbp
    12b3:	48 89 e5             	mov    %rsp,%rbp
    12b6:	48 83 ec 10          	sub    $0x10,%rsp
    12ba:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)
    12be:	48 8d 3d 4b 0d 00 00 	lea    0xd4b(%rip),%rdi        # 2010 <_ZStL19piecewise_construct+0xc>
    12c5:	e8 e6 fd ff ff       	callq  10b0 <puts@plt>
    12ca:	90                   	nop
    12cb:	c9                   	leaveq 
    12cc:	c3                   	retq   
    12cd:	90                   	nop

00000000000012ce <_ZN7Derived11derive_demoEv>:
    12ce:	f3 0f 1e fa          	endbr64 
    12d2:	55                   	push   %rbp
    12d3:	48 89 e5             	mov    %rsp,%rbp
    12d6:	48 83 ec 10          	sub    $0x10,%rsp
    12da:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)
    12de:	48 8d 3d 38 0d 00 00 	lea    0xd38(%rip),%rdi        # 201d <_ZStL19piecewise_construct+0x19>
    12e5:	e8 c6 fd ff ff       	callq  10b0 <puts@plt>
    12ea:	90                   	nop
    12eb:	c9                   	leaveq 
    12ec:	c3                   	retq   
    12ed:	90                   	nop

00000000000012ee <_ZN7Derived13derive_demo_2Ev>:
    12ee:	f3 0f 1e fa          	endbr64 
    12f2:	55                   	push   %rbp
    12f3:	48 89 e5             	mov    %rsp,%rbp
    12f6:	48 83 ec 10          	sub    $0x10,%rsp
    12fa:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)
    12fe:	48 8d 3d 26 0d 00 00 	lea    0xd26(%rip),%rdi        # 202b <_ZStL19piecewise_construct+0x27>
    1305:	e8 a6 fd ff ff       	callq  10b0 <puts@plt>
    130a:	90                   	nop
    130b:	c9                   	leaveq 
    130c:	c3                   	retq   
    130d:	0f 1f 00             	nopl   (%rax)

/*
 * arm
 */
000000000040076c <main>:
  40076c:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400770:	910003fd 	mov	x29, sp
  400774:	910063a0 	add	x0, x29, #0x18				// x0=x29+0x18
  400778:	9400002d 	bl	40082c <_ZN4Base4demoEv>		// base.demo(x0)
  40077c:	910063a0 	add	x0, x29, #0x18				// x0=x29+0x18
  400780:	94000034 	bl	400850 <_ZN4Base6demo_2Ev>		// base.demo_2(x0)
  400784:	910043a0 	add	x0, x29, #0x10				// x0=x29+0x10
  400788:	94000029 	bl	40082c <_ZN4Base4demoEv>		// base.demo(x0)
  40078c:	910043a0 	add	x0, x29, #0x10				// x0=x29+0x10
  400790:	94000030 	bl	400850 <_ZN4Base6demo_2Ev>		// base.demo_2(x0)
  400794:	910043a0 	add	x0, x29, #0x10				// x0=x29+0x10
  400798:	94000037 	bl	400874 <_ZN7Derived11derive_demoEv>	// derive_demo(x0)
  40079c:	910043a0 	add	x0, x29, #0x10				// x0=x29+0x10
  4007a0:	9400003e 	bl	400898 <_ZN7Derived13derive_demo_2Ev>	// derive_demo_2(x0)
  4007a4:	52800000 	mov	w0, #0x0                   	// #0
  4007a8:	a8c27bfd 	ldp	x29, x30, [sp], #32
  4007ac:	d65f03c0 	ret

000000000040082c <_ZN4Base4demoEv>:
  40082c:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400830:	910003fd 	mov	x29, sp
  400834:	f9000fa0 	str	x0, [x29, #24]			// x29+24=x0
  400838:	90000000 	adrp	x0, 400000 <_init-0x5c8>	// x0=400000
  40083c:	9125e000 	add	x0, x0, #0x978			// x0=400978
  400840:	97ffff88 	bl	400660 <puts@plt>		// puts(x0)
  400844:	d503201f 	nop
  400848:	a8c27bfd 	ldp	x29, x30, [sp], #32
  40084c:	d65f03c0 	ret

0000000000400850 <_ZN4Base6demo_2Ev>:
  400850:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400854:	910003fd 	mov	x29, sp
  400858:	f9000fa0 	str	x0, [x29, #24]
  40085c:	90000000 	adrp	x0, 400000 <_init-0x5c8>
  400860:	91262000 	add	x0, x0, #0x988
  400864:	97ffff7f 	bl	400660 <puts@plt>
  400868:	d503201f 	nop
  40086c:	a8c27bfd 	ldp	x29, x30, [sp], #32
  400870:	d65f03c0 	ret

0000000000400874 <_ZN7Derived11derive_demoEv>:
  400874:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400878:	910003fd 	mov	x29, sp
  40087c:	f9000fa0 	str	x0, [x29, #24]
  400880:	90000000 	adrp	x0, 400000 <_init-0x5c8>
  400884:	91266000 	add	x0, x0, #0x998
  400888:	97ffff76 	bl	400660 <puts@plt>
  40088c:	d503201f 	nop
  400890:	a8c27bfd 	ldp	x29, x30, [sp], #32
  400894:	d65f03c0 	ret

0000000000400898 <_ZN7Derived13derive_demo_2Ev>:
  400898:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  40089c:	910003fd 	mov	x29, sp
  4008a0:	f9000fa0 	str	x0, [x29, #24]
  4008a4:	90000000 	adrp	x0, 400000 <_init-0x5c8>
  4008a8:	9126a000 	add	x0, x0, #0x9a8
  4008ac:	97ffff6d 	bl	400660 <puts@plt>
  4008b0:	d503201f 	nop
  4008b4:	a8c27bfd 	ldp	x29, x30, [sp], #32
  4008b8:	d65f03c0 	ret
  4008bc:	00000000 	.inst	0x00000000 ; undefined

 #endif
